<template>
	<view class="paymentList-view">
		<view class="tit">{{tit}}订单{{orderList.length}}</view>
		<order-list :list="orderList" :isDetail="isOrder"></order-list>
	</view>
</template>

<script>
	const util = require("../../utils/util.js");
	//获取应用实例
	const api = require("../../config/api.js"); 
	import orderList from "../../components/orderList/orderList"; 
	export default {
		data() {
			return {
				index:0,
				// 拒绝理由
				reasonRefusal:'',
				// 订单遮罩控制
				orderDrop:false,
				tit:'',
				page:1,
				orderList:[],
				// 到付订单
				collectOrder:1,
				// 预付款
				prePayOrder:1,
				// 赊账
				inCreditOrder:1,
				// 状态
				status:'',
				salesmanagerId:'',
				userInfo:'',
				isOrder:false
				
			}
		},
		components: {
		  orderList
		},
		onPullDownRefresh() {
			this.page=1
		    this.getOrderList()
			
		},
		// 上拉加载
		onReachBottom(){
			uni.showNavigationBarLoading();//显示加载动画
			this.page++;
			
			console.log(this.active)
			console.log(this.salesmanagerId)
			util.request(api.businessOrderList+'?page='+this.page+'&size=20',
			this.active
			, 'POST').then(res => {
				console.log(res)
				if(res.error==0){
					if(this.page>1){
						 if(res.data.data.length==0){
						 	if(this.page>1){
						 		uni.hideNavigationBarLoading();//关闭加载动画
								this.dx=true
							}
						}else{
							this.orderList = [...this.orderList,...res.data.data]
						}
						
					}
					uni.hideNavigationBarLoading();//关闭加载动画
					
				}
				
				
			})
		},
		onLoad(json){
			this.index = json.index;
			this.salesmanagerId = json.userId;
			this.tit = json.tit 
			console.log(this.salesmanagerId)
			// #ifdef APP-PLUS
			let currentWebview = this.$mp.page.$getAppWebview();
				currentWebview.setStyle({
				titleNView: {
				titleText:json.tit
				},
			})
			// #endif
		},
		onShow() {
			this.page=1
			this.getOrderList();
		},
		methods: {
			// 子组件修改父组件的值
			pages(res){
				console.log('子组件返回的值')
				console.log(res)
				this.page = 1
			},
			getOrderList(){
				if(this.index==1){
					this.isOrder = false;
					this.active = {
						prePayOrder:1,
						userId:this.salesmanagerId
					}
					util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
						prePayOrder:1,
						userId:this.salesmanagerId
					}, 'POST').then(res => {
						console.log(res)
						this.orderList = res.data.data
						
						uni.stopPullDownRefresh()
						
					})
				}
				if(this.index==2){
					this.isOrder = false;
					this.active = {
						collectOrder:1,
						userId:this.salesmanagerId
					}
					util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
						collectOrder:1,
						userId:this.salesmanagerId
					}, 'POST').then(res => {
						console.log(res)
						this.orderList = res.data.data
						uni.stopPullDownRefresh()
					})
				}
				if(this.index==3){
					this.isOrder = true;
					console.log(this.isOrder)
					this.active = {
						inCreditOrder:1,
						userId:this.salesmanagerId
					}
					util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
						inCreditOrder:1,
						userId:this.salesmanagerId
					}, 'POST').then(res => {
						console.log(res)
						this.orderList = res.data.data
						
						uni.stopPullDownRefresh()
						
					})
				}
				
				if(this.index==4){
					this.isOrder = false;
					this.active = {
						inTransferPayOrder:1,
						userId:this.salesmanagerId
					}
					util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
						inTransferPayOrder:1,
						userId:this.salesmanagerId
					}, 'POST').then(res => {
						console.log(res)
						this.orderList = res.data.data
						
						uni.stopPullDownRefresh()
						
					})
				}
				
				
				
			}
		}
	}
</script>

<style>
	@import url("./paymentList.css");
</style>
